/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leoz
 */
@Entity
@Table(name = "song")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Song.findAll", query = "SELECT s FROM Song s"),
    @NamedQuery(name = "Song.findByIdSong", query = "SELECT s FROM Song s WHERE s.songPK.idSong = :idSong"),
    @NamedQuery(name = "Song.findByTitle", query = "SELECT s FROM Song s WHERE s.title = :title"),
    @NamedQuery(name = "Song.findByDuration", query = "SELECT s FROM Song s WHERE s.duration = :duration"),
    @NamedQuery(name = "Song.findByArtistidArtist", query = "SELECT s FROM Song s WHERE s.songPK.artistidArtist = :artistidArtist")})
public class Song implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SongPK songPK;
    @Basic(optional = false)
    @Column(name = "title")
    private String title;
    @Basic(optional = false)
    @Column(name = "duration")
    private float duration;
    @JoinColumn(name = "Artist_idArtist", referencedColumnName = "idArtist", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Artist artist;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "song")
    private Collection<Soundtrack> soundtrackCollection;

    public Song() {
    }

    public Song(SongPK songPK) {
        this.songPK = songPK;
    }

    public Song(SongPK songPK, String title, float duration) {
        this.songPK = songPK;
        this.title = title;
        this.duration = duration;
    }

    public Song(int idSong, int artistidArtist) {
        this.songPK = new SongPK(idSong, artistidArtist);
    }

    public SongPK getSongPK() {
        return songPK;
    }

    public void setSongPK(SongPK songPK) {
        this.songPK = songPK;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public float getDuration() {
        return duration;
    }

    public void setDuration(float duration) {
        this.duration = duration;
    }

    public Artist getArtist() {
        return artist;
    }

    public void setArtist(Artist artist) {
        this.artist = artist;
    }

    @XmlTransient
    public Collection<Soundtrack> getSoundtrackCollection() {
        return soundtrackCollection;
    }

    public void setSoundtrackCollection(Collection<Soundtrack> soundtrackCollection) {
        this.soundtrackCollection = soundtrackCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (songPK != null ? songPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Song)) {
            return false;
        }
        Song other = (Song) object;
        if ((this.songPK == null && other.songPK != null) || (this.songPK != null && !this.songPK.equals(other.songPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Song[ songPK=" + songPK + " ]";
    }
    
}
